#include "camera.h"

glm::mat4 Camera::getView() {
    return glm::lookAt(Position, Position + Front, WorldUp);
}

void Camera::processKey(CAMERA_DIRECTION direction, float deltaTime)
{
    float cameraSpeed = moveSpeed * deltaTime; 
    if (direction == FORWARD)
        Position += cameraSpeed * Front;
    if (direction == BACKWARD)
        Position -= cameraSpeed * Front;
    if (direction == LEFT)
        Position -= glm::normalize(glm::cross(Front, WorldUp)) * cameraSpeed;
    if (direction == RIGHT)
        Position += glm::normalize(glm::cross(Front, WorldUp)) * cameraSpeed;
}

void Camera::round(float xoffset, float yoffset) {
    xoffset *= mouseSensivity;
    yoffset *= mouseSensivity;
    
    yaw += xoffset;
    pitch += yoffset;
    
    if (pitch > 89) pitch = 89.0f;
    if (pitch < -89) pitch = -89.0f;
    
    updateCamera();
}

void Camera::scroll(double yoffset)
{
  if(zoom >= 1.0f && zoom <= 45.0f)
    zoom -= yoffset;
  if(zoom <= 1.0f)
    zoom = 1.0f;
  if(zoom >= 45.0f)
    zoom = 45.0f;
}
void Camera::updateCamera() {
    // std::cout<<"("<<yaw<<", "<<pitch<<")"<<std::endl;
    glm::vec3 front;
    front.x = cos(glm::radians(pitch)) * cos(glm::radians(yaw));
    front.y = sin(glm::radians(pitch));
    front.z = cos(glm::radians(pitch)) * sin(glm::radians(yaw));
    Front = glm::normalize(front);
    Right = glm::normalize(glm::cross(Front, WorldUp));
    Up = glm::normalize(glm::cross(Front, Right));
}